﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GameSchool.Models.Interfaces;

namespace GameSchool.Models.Repositories
{
    public class LectureRepository : ILectureRepository
    {
        GameSchoolDBDataContext db = new GameSchoolDBDataContext();


        //Fetches all Lectures
        public IQueryable<Lecture> GetLectures()
        {
            return db.Lectures;
        }


        public void AddLecture(Lecture l)
        {
            db.Lectures.InsertOnSubmit(l);
        }

        //Fetches a lecture by it's ID
        public Lecture GetLectureByID(int? lID)
        {
            var lec = (from Lecture in db.Lectures
                       where Lecture.ID == lID
                       select Lecture).SingleOrDefault();

            return lec;
        }

        //Deletes a Lecture by it's ID
        public void DeleteLecture(int? lID)
        {
            var lec = (from n in db.Lectures
                       where n.ID == lID
                       select n).SingleOrDefault();
            if (lec != null)
            {
                db.Lectures.DeleteOnSubmit(lec);
            }
        }

        public void Save()
        {
            db.SubmitChanges();
        }

    }

}